version: '3.9'

services:
  db:
    image: postgres:15
    volumes:
      - app-db-data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    networks:
      - application
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U postgres']
      interval: 5s
      timeout: 5s
      retries: 5

  pgadmin:
    image: dpage/pgadmin4
    depends_on:
      db:
        condition: service_healthy
    ports:
      - 5050:80
    networks:
      - application
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD}

  app:
    build:
      context: .
      args:
        NEXT_PUBLIC_CDN_ENDPOINT_URL: ${NEXT_PUBLIC_CDN_ENDPOINT_URL}
        NEXT_PUBLIC_S3_UPLOAD_RESOURCE_FORMATS: ${NEXT_PUBLIC_S3_UPLOAD_RESOURCE_FORMATS}
        NEXT_PUBLIC_NEXTAUTH_URL: ${NEXT_PUBLIC_NEXTAUTH_URL}
    depends_on:
      db:
        condition: service_healthy
    ports:
      - 3000:3000
    networks:
      - application
    environment:
      DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}
      ANALYZE: ${ANALYZE}
      DISABLE_PWA: ${DISABLE_PWA}
      S3_UPLOAD_KEY: ${S3_UPLOAD_KEY}
      S3_UPLOAD_SECRET: ${S3_UPLOAD_SECRET}
      S3_UPLOAD_BUCKET: ${S3_UPLOAD_BUCKET}
      S3_UPLOAD_HOSTNAME: ${S3_UPLOAD_HOSTNAME}
      S3_UPLOAD_ENDPOINT_URL: ${S3_UPLOAD_ENDPOINT_URL}
      S3_UPLOAD_REGION: ${S3_UPLOAD_REGION}
      NEXT_PUBLIC_S3_UPLOAD_RESOURCE_FORMATS: ${NEXT_PUBLIC_S3_UPLOAD_RESOURCE_FORMATS}
      OPENAI_API_KEY: ${OPENAI_API_KEY}
      UPSTASH_REDIS_REST_URL: ${UPSTASH_REDIS_REST_URL}
      UPSTASH_REDIS_REST_TOKEN: ${UPSTASH_REDIS_REST_TOKEN}
      NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}
      NEXTAUTH_URL: ${NEXTAUTH_URL}
      NEXT_PUBLIC_NEXTAUTH_URL: ${NEXT_PUBLIC_NEXTAUTH_URL}
      MIREA_CLIENT_ID: ${MIREA_CLIENT_ID}
      MIREA_CLIENT_SECRET: ${MIREA_CLIENT_SECRET}
      GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
      GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET}
      GITHUB_CLIENT_ID: ${GITHUB_CLIENT_ID}
      GITHUB_CLIENT_SECRET: ${GITHUB_CLIENT_SECRET}

networks:
  application:

volumes:
  app-db-data:
